<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Sets the RNG seed</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="function.gmp-random-range.html">« gmp_random_range</a></li>
      <li style="float: right;"><a href="function.gmp-random.html">gmp_random »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.gmp.html">GMP 函数</a></li>
    <li>Sets the RNG seed</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="function.gmp-random-seed" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">gmp_random_seed</h1>
  <p class="verinfo">(PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">gmp_random_seed</span> &mdash; <span class="dc-title">Sets the RNG seed</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.gmp-random-seed-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>gmp_random_seed</strong></span>(<span class="methodparam"><span class="type"><span class="type"><a href="class.gmp.html" class="type GMP">GMP</a></span>|<span class="type">int</span>|<span class="type">string</span></span> <code class="parameter">$seed</code></span>): <span class="type"><span class="type void">void</span></span></div>

 </div>


 <div class="refsect1 parameters" id="refsect1-function.gmp-random-seed-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">seed</code></dt>

     <dd>

      <p class="para">
       The seed to be set for the <span class="function"><a href="function.gmp-random.html" class="function">gmp_random()</a></span>,
       <span class="function"><a href="function.gmp-random-bits.html" class="function">gmp_random_bits()</a></span>, and
       <span class="function"><a href="function.gmp-random-range.html" class="function">gmp_random_range()</a></span> functions.
      </p>

      <p class="para"><span class="classname"><a href="class.gmp.html" class="classname">GMP</a></span> 对象或 <span class="type">int</span> ，或数字<span class="type">string</span>。</p> 
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.gmp-random-seed-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   没有返回值。
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-function.gmp-random-seed-errors">
  <h3 class="title">错误／异常</h3>
  <p class="para">
   Throws a <span class="classname"><a href="class.valueerror.html" class="classname">ValueError</a></span> if <code class="parameter">seed</code>
   is invalid.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.gmp-random-seed-changelog">
  <h3 class="title">更新日志</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>版本</th>
      <th>说明</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>8.0.0</td>
      <td>
       If <code class="parameter">seed</code> is invalid, <span class="function"><strong>gmp_random_seed()</strong></span>
       now throws a <span class="classname"><a href="class.valueerror.html" class="classname">ValueError</a></span>.
       Previously it emitted an <strong><code>E_WARNING</code></strong> and returned <strong><code>false</code></strong>.
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-function.gmp-random-seed-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-3067">
    <p><strong>示例 #1 <span class="function"><strong>gmp_random_seed()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;set&nbsp;the&nbsp;seed<br /></span><span style="color: #0000BB">gmp_random_seed</span><span style="color: #007700">(</span><span style="color: #0000BB">100</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">gmp_strval</span><span style="color: #007700">(</span><span style="color: #0000BB">gmp_random</span><span style="color: #007700">(</span><span style="color: #0000BB">1</span><span style="color: #007700">)));<br /><br /></span><span style="color: #FF8000">//&nbsp;set&nbsp;the&nbsp;seed&nbsp;to&nbsp;something&nbsp;else<br /></span><span style="color: #0000BB">gmp_random_seed</span><span style="color: #007700">(</span><span style="color: #0000BB">gmp_init</span><span style="color: #007700">(-</span><span style="color: #0000BB">100</span><span style="color: #007700">));<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">gmp_strval</span><span style="color: #007700">(</span><span style="color: #0000BB">gmp_random_bits</span><span style="color: #007700">(</span><span style="color: #0000BB">10</span><span style="color: #007700">)));<br /><br /></span><span style="color: #FF8000">//&nbsp;set&nbsp;the&nbsp;seed&nbsp;to&nbsp;something&nbsp;invalid<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">gmp_random_seed</span><span style="color: #007700">(</span><span style="color: #DD0000">'not&nbsp;a&nbsp;number'</span><span style="color: #007700">));</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程会输出：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
string(20) &quot;15370156633245019617&quot;
string(3) &quot;683&quot;

Warning: gmp_random_seed(): Unable to convert variable to GMP - string is not an integer in %s on line %d
bool(false)
</pre></div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.gmp-random-seed-seealso">
  <h3 class="title">参见</h3>
  <ul class="simplelist">
   <li class="member"><span class="function"><a href="function.gmp-init.html" class="function" rel="rdfs-seeAlso">gmp_init()</a> - Create GMP number</span></li>
   <li class="member"><span class="function"><a href="function.gmp-random.html" class="function" rel="rdfs-seeAlso">gmp_random()</a> - Random number</span></li>
   <li class="member"><span class="function"><a href="function.gmp-random-bits.html" class="function" rel="rdfs-seeAlso">gmp_random_bits()</a> - Random number</span></li>
   <li class="member"><span class="function"><a href="function.gmp-random-range.html" class="function" rel="rdfs-seeAlso">gmp_random_range()</a> - Random number</span></li>
  </ul>
 </div>


</div></div></div></body></html>